
#include "md5_hash.h"

// 实现compute_md5_hash函数
char* compute_md5_hash(const char *str, char *md5_string) {
    unsigned char md5_result[MD5_HASH_LENGTH];
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
    const EVP_MD *md = EVP_md5();

    EVP_DigestInit_ex(ctx, md, NULL);
    EVP_DigestUpdate(ctx, str, strlen(str));
    EVP_DigestFinal_ex(ctx, md5_result, NULL);

    EVP_MD_CTX_free(ctx);

    for (int i = 0; i < MD5_HASH_LENGTH; i++) {
        sprintf(&md5_string[i * 2], "%02x", md5_result[i]);
    }
    md5_string[MD5_STRING_LENGTH - 1] = '\0'; // 确保字符串以null结尾

    return md5_string;
}
